package com.taptech.doufu.ui.adapter

import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.taptech.doufu.R
import com.taptech.doufu.bean.ShareBeansInfo
import com.taptech.doufu.constant.ShareType
import com.taptech.doufu.constant.UmengEventName
import com.taptech.doufu.ktexpand.format
import com.taptech.doufu.model.novel.bean.NovelDetailBean
import com.taptech.doufu.ui.activity.BrowseActivity
import com.taptech.doufu.ui.activity.story.StoryCodeActivity
import com.taptech.doufu.ui.activity.story.StoryDetailsActivity
import com.taptech.doufu.util.ShareUtils
import com.taptech.doufu.util.StringUtil
import com.taptech.doufu.util.TMAnalysis
import com.taptech.doufu.util.TimeDateFunction
import kotlinx.android.synthetic.main.adapter_my_story.view.*

class MyStoryAdapter(context:Context): BaseRecyclerAdappter<NovelDetailBean,MyStoryAdapter.ViewHolder>(context){

    interface OnRightBtnClickListener{
        fun onClick(item:NovelDetailBean,position: Int)
    }

    var onRightBtnClickListener:OnRightBtnClickListener? = null
        set(value) {
            field = value
        }


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(mContext).inflate(R.layout.adapter_my_story,null)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        val item = dataList[position]
        holder.itemView.tvTitle.text = item.title
        holder.itemView.tvTime.text = "更新：${TimeDateFunction.toDateTime(item.update_time*1000)}"
        when (item.audit_status) {
            0->{//正常
                holder.itemView.tvState.setTextColor(ContextCompat.getColor(mContext,R.color.text_color_8993A3))
                holder.itemView.tvState.text = "已发布 阅读：${item.read_times.toInt().format()}"
            }
            1->{//未发布
                holder.itemView.tvState.setTextColor(ContextCompat.getColor(mContext,R.color.text_color_8993A3))
                holder.itemView.tvState.text = "未发布"
            }
            2->{//审核中
                holder.itemView.tvState.setTextColor(Color.parseColor("#46BDA8"))
                holder.itemView.tvState.text = "审核中"
            }
            3->{//审核未通过
                holder.itemView.tvState.setTextColor(ContextCompat.getColor(mContext,R.color.text_color_57))
                holder.itemView.tvState.text = "审核未通过"
            }
        }
        if (item.status == 1 && item.is_recommend == 1) {
            holder.itemView.tvPreview.visibility = View.VISIBLE
        }else{
            holder.itemView.tvPreview.visibility = View.GONE
        }
        holder.itemView.tvPreview.setOnClickListener {
            StoryDetailsActivity.startActivity(mContext,item.id)
        }
        holder.itemView.layMore.setOnClickListener {
            onRightBtnClickListener?.onClick(item,position)
        }
        holder.itemView.setOnClickListener {
            StoryCodeActivity.startActivity(mContext,item.id)
        }
    }

    class ViewHolder(view: View): RecyclerView.ViewHolder(view)
}